import VueRouter from 'vue-router'

import HomeContainer from './components/tabber/HomeContainer.vue'
import MemberContainer from './components/tabber/MemberContainer.vue'
import Fenlei from './components/tabber/Fenlei.vue'
import ShopcarContainer from './components/tabber/ShopcarContainer.vue'
import tuijian from './components/childen/tuijian.vue'
import baihuo from './components/childen/baihuo.vue'
import muying from './components/childen/muying.vue'
import nanzhuang from './components/childen/nanzhuang.vue'
import nvzhuang from './components/childen/nvzhuang.vue'
import shiping from './components/childen/shiping.vue'
import xiebao from './components/childen/xiebao.vue'
import container from './components/container/shop.vue'
import shopcomment from './components/container/shopconment.vue'
import infodesc from './components/container/infodesc.vue'
import register from './components/subcomponent/register.vue'
import menberman from './components/submember/Menberfavorites.vue'
import goodsList from './components/subcomponent/tuijianzizujianneirong.vue'
import xianshimiaosha from './components/active/subsidy.vue'
// 3. 创建路由对象
var router = new VueRouter({
	routes: [
		{ path: '/' ,redirect: '/home/tuijian' },
		{ path: '/home' ,component: HomeContainer,children:[
			{path:'tuijian',component:tuijian },
			{path:'xiebao',component:xiebao },
			{path:'shiping',component:shiping },
			{path:'nvzhuang',component:nvzhuang },
			{path:'nanzhuang',component:nanzhuang },
			{path:'muying',component:muying },
			{path:'baihuo',component:baihuo },
			]},
		{ path: '/home/container/:id' ,component:container },
		{ path: '/member' ,component: MemberContainer ,name:'member' },
		{ path: '/shopcar' ,component: ShopcarContainer,name:"shopcar" },
		{ path: '/fenlei' ,component:Fenlei },
		{ path:'/shop/comment' ,component:shopcomment ,name:'infocomment'},
		{ path:'/shop/info' ,component:infodesc ,name:'infodesc'},
		{ path:'/register' ,component:register ,name:'register'},
		{ path:'/menberman' , component:menberman },
		{ path:'/goodsList' , component: goodsList },
		{ path:'/xianshimiaosha' , component: xianshimiaosha }
	],
	linkActiveClass: "mui-active"
})

// console.log(router.app.$options.store.state.userLogin)
// 	var isAuthenticated = router.app.$options.store.state.userLogin
//前端路由守卫
router.beforeEach((to, from, next) => {
	// 获取vuex中state的数据
		var isAuthenticated = router.app.$options.store.state.userLogin
	// next()
	if(isAuthenticated) next()
	else if(to.name == 'member') next()
	else if(to.name == 'register') next()
	else  next({ name: 'member' })
	// if (to.name !== 'member' && !isAuthenticated) next({ name: 'member' })
	// else next()
})

//把路由对象暴露出去
export default router
